<template>
	<div class="search-results">
		<van-list
		  v-model="loading"
		  :finished="finished"
		  finished-text="没有更多了"
		  @load="onLoad"
		>
		  <van-cell v-for="(item,index) in list" :key="index" :title="item.title" />
		</van-list>
	</div>
</template>

<script>
	import { getSearchResult } from '../../../utils/search.js'
	
	export default {
		name:"SearchResults",
		props:{
			searchText: {
				type:String,
				required: true,
				
			}
		},
		data() {
			return {
				list: [],
				loading: false,
				finished: false,
				
				page:1, //页码
				perPage: 10 //每页大小
			}
		},
		methods: {
			async onLoad() {
			    const { data } = await getSearchResult({
						page: this.page,
						per_page: this.perPage,
						q:this.searchText
					})
					const { results } = data.data
					this.list.push(...results)
					
					this.loading = false
					
					if(results.length) {
						this.page++
					}else {
						this.finished = true
					}
			},
		}
	}
</script>

<style>
</style>
